﻿using System;
using System.IO;
using System.Text;
using SSAT.Utils;

namespace SSAT.Controls
{
    internal sealed class ConsoleFieldOutStream : TextWriter
    {
        private readonly Action<string> _receiver;

        public override Encoding Encoding
        {
            get { throw new NotImplementedException(); }
        }

        public ConsoleFieldOutStream(Action<string> receiveCallback)
        {
            Verification.CheckArgumentForNull(receiveCallback, "receiveCallback");
            _receiver = receiveCallback;
        }

        public override void Write(char value)
        {
            WriteToReceiver(value.ToString());
        }

        public override void Write(char[] buffer, int startIndex, int length)
        {
            WriteToReceiver(new string(buffer, startIndex, length));
        }

        private void WriteToReceiver(string text)
        {
            _receiver.Invoke(text);
        }
    }
}
